package img

import(
	"plugin"
	"context"
	"runtime"
	"fmt"

	// "goauto/model"
)


var pPlugin *plugin.Plugin
var soPath string = "/src/goauto/.so/library/sent_data/pkg.so"

func init() {
	initPlugin()
}

func initPlugin() {
	if pPlugin == nil {
		goroot := runtime.GOROOT()
		soPath := goroot + soPath
		fmt.Println("soPath", soPath)
		pPluginTmp, errTmp := plugin.Open(soPath)
		if errTmp != nil {
			panic(errTmp)
		}
		pPlugin = pPluginTmp
	}
	
	return
}

func AutoGetPopRouteNo(ctx context.Context) (ctx2 context.Context, recvData map[string]any, nextRouteNo string) {
	
	AutoGetPopRouteNo2, err := pPlugin.Lookup("AutoGetPopRouteNo")
	if err != nil {
		panic(err)
	}
	ctx2, recvData, nextRouteNo = AutoGetPopRouteNo2.(func(context.Context)(context.Context, map[string]any, string))(ctx)
	return
}

func PanicRecvData(recvData map[string]any) (sentData map[string]any) {
	
	PanicRecvData2, err := pPlugin.Lookup("PanicRecvData")
	if err != nil {
		panic(err)
	}
	sentData = PanicRecvData2.(func(map[string]any)(map[string]any))(recvData)
	return
}